<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>首页</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="../../layui/css/layui.css"
	media="all">
<link rel="stylesheet" href="../../res/js/tl/admin.css"
	media="all">
<style type="text/css">
	/*滚动条样式*/
    .innerbox::-webkit-scrollbar {/*滚动条整体样式*/
        width: 6px;     /*高宽分别对应横竖滚动条的尺寸*/
        height: 6px;
    }
    .innerbox::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
        border-radius: 10px;
        -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
        background: rgba(0,0,0,0.2);
    }
    .innerbox::-webkit-scrollbar-track {/*滚动条里面轨道*/
        -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
        border-radius: 0;
        background: rgba(0,0,0,0.1);
    }
    .layui-input{
    	border:none;
    }
    .layui-col-md3{
    	width:25%;
    }
    .zc{
    	width:100%;
    	height:30px;
    	background-color:#F0F0F0;
    }
    .span{
    	display:block;
    	float:left;
    	width:46%;
    	line-height:30px;
    	padding:0px 2%;
    }
    .zc_centent{
    	width:100%;
    	height:30px;
    	border-bottom:1px dashed  #c2c2c2;
    }
    .zc_centent:hover{
    	background-color:#F0F0F0;
    }
</style>
</head>
<body class="innerbox" onload="pdOne();pdTwo();">
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">

			<div class="layui-col-sm6 layui-col-md3">
				<div class="layui-card">
					<div class="layui-card-header">
						库存预警<span class="layui-badge layui-bg-blue layuiadmin-badge">条</span>
					</div>
					<div class="layui-card-body layuiadmin-card-list">
						<p class="layuiadmin-big-font" id="repertory_earlyWarning"></p>
						<p>
							<a href="#inventoryRecord" class="layui-btn layui-btn-xs">查看详情</a><span class="layuiadmin-span-color"> <i
								class="layui-inline layui-icon layui-icon-flag"></i></span>
						</p>
					</div>
				</div>
			</div>
			<div class="layui-col-sm6 layui-col-md3">
				<div class="layui-card">
					<div class="layui-card-header">
						今日销量<span class="layui-badge layui-bg-cyan layuiadmin-badge">日</span>
					</div>
					<div class="layui-card-body layuiadmin-card-list">
						<p class="layuiadmin-big-font" id="todaysSales"></p>
						<p>
							本月销量 <span class="layuiadmin-span-color" id="monthSales"><i
								class="layui-inline layui-icon layui-icon-face-smile-b"></i></span>
						</p>
					</div>
				</div>
			</div>
			<div class="layui-col-sm6 layui-col-md3">
				<div class="layui-card">
					<div class="layui-card-header">
						今日收入(纯收入) <span class="layui-badge layui-bg-green layuiadmin-badge">日</span>
					</div>
					<div class="layui-card-body layuiadmin-card-list">

						<p class="layuiadmin-big-font" id="todaysIncome"></p>
						<p>
							本月收入(纯收入) <span class="layuiadmin-span-color" id="monthIncome"><i
								class="layui-inline layui-icon layui-icon-rmb"></i></span>
						</p>
					</div>
				</div>
			</div>
			<!-- <div class="layui-col-sm6 layui-col-md3">
				<div class="layui-card">
					<div class="layui-card-header">
						等待您审核 <span class="layui-badge layui-bg-orange layuiadmin-badge">条</span>
					</div>
					<div class="layui-card-body layuiadmin-card-list">

						<p class="layuiadmin-big-font">66,666</p>
						<p>
							已审核 <span class="layuiadmin-span-color">15% <i
								class="layui-inline layui-icon layui-icon-user"></i></span>
						</p>
					</div>
				</div>
			</div> -->
			<div class="layui-col-sm6 layui-col-md3">
				<div class="layui-card">
					<div class="layui-card-header">
						财务总金额<span class="layui-badge layui-bg-orange layuiadmin-badge">元</span>
					</div>
					<div class="layui-card-body layuiadmin-card-list">

						<p class="layuiadmin-big-font sumMoney"></p>
						<p>
							财务总金额<span class="layuiadmin-span-color sumMoney"><i
								class="layui-inline layui-icon layui-icon-rmb"></i></span>
						</p>
					</div>
				</div>
			</div>
			<div class="layui-col-sm8" style="width:100%">
				<div class="layui-row layui-col-space15">
					<div class="layui-col-sm6">
						<div class="layui-card">
							<div class="layui-card-header">
								药品年销售量占年总销售的百分比
								<div class="layuiadmin-btn-group" style="position:absolute;top:0px;">
									<div class="layui-inline">
									<div class="layui-input-inline">
										<input type="text" class="layui-input year" id="dateThree"
											placeholder="请选择年份" style="height:30px;width:120px;position:relative;top:-2px;left:-10px;">
									</div>
								</div>
								</div>
							</div>
							<div class="layui-card-body" id="salesProportion" style="width:100%;height:316px">
								
							</div>
						</div>
					</div>
					<div class="layui-col-sm6">
						<div class="layui-card">
							<div class="layui-card-header">政策维护
								<div class="layuiadmin-btn-group" style="position:absolute;top:0px;">
									<a href="javascript:;" id="policyDetail" class="layui-btn layui-btn-xs">查看详情</a>
								</div>
							</div>
							<div class="layui-card-body innerbox" style="overflow-x: auto; overflow-y: auto; height: 315px; width:94%;">
								<!-- <table class="layui-table" lay-data="{height:315, url:'../../policy/findAll.action', page:true, id:'test',size:'sm'}" lay-filter="test">
								  <thead>
								    <tr>
								      <th lay-data="{field:'policyName', width:80}">政策名称</th>
								      <th lay-data="{field:'policyComment', width:80}">政策内容</th>
								      <th lay-data="{field:'policyPerson', width:80}">政策发布人</th>
								      <th lay-data="{field:'policyTime', width:80}">发布时间</th>
								      <th lay-data="{field:'company_name', width:80}">公司名称</th>
								    </tr>
								  </thead>
								</table> -->
								<div class="zc">
									<span class="span">政策标题</span>
									<span class="span">发布时间</span>
								</div>
								<div id="centent">
									<marquee id="centent_nr" direction="up" scrollamount="2" loop="infinite" style="width:100%;height:270px;" onMouseOut="this.start()"onMouseOver="this.stop()">
									
									</marquee>
									<!-- <a href="#">
										<div class="zc_centent">
											<span class="span">政策标题</span>
											<span class="span">发布时间</span>
										</div>
									</a> -->
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-col-sm12">
				<div class="layui-card">
					<div class="layui-card-header">
						销售量排名前十数据统计&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="layui-btn layui-btn-xs" href="#tongji">查看详情</a>
						<div class="layuiadmin-btn-group" style="position:absolute;top:0px;">
							<div class="layui-inline">
								<div class="layui-input-inline">
									<input type="text" class="layui-input year" id="dateOne"
										placeholder="请选择年份" style="height:30px;width:120px;position:relative;top:-2px;left:-10px;">
								</div>
							</div>
						</div>
					</div>
					<div class="layui-card-body">
						<div class="layui-row">
							<div class="layui-col-sm8 innerbox" style="width:100%;overflow-x:auto;">
								<div id="salesNumber" style="width:100%;height:400px;">
									
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-col-sm12">
				<div class="layui-card">
					<div class="layui-card-header">
						销售总金额与成本总金额对比图&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;销售总金额及毛利对比图
						<div class="layuiadmin-btn-group" style="position:absolute;top:0px;">
							<div class="layui-inline">
							<div class="layui-input-inline">
								<input type="text" class="layui-input year" id="dateTwo"
									placeholder="请选择年份" style="height:30px;width:120px;position:relative;top:-2px;left:-10px;">
							</div>
						</div>
						</div>
					</div>
					<div class="layui-card-body">
						<div class="layui-row">
							<div class="layui-col-sm8 innerbox" style="width:50%;overflow-x:auto;">
								<div id="salesPrice" style="width:100%;height:400px;">
									
								</div>
							</div>
							<div class="layui-col-sm4 innerbox" style="width:50%;overflow-x:auto;">
								<div id="salesSumMoney" style="width:100%;height:400px;">
								
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-col-sm8" style="width:100%">
				<div class="layui-row layui-col-space15">
					
					<div class="layui-col-sm6">
						<div class="layui-card">
							<div class="layui-card-header">
								<a name="tongji">销售量数排行表(每年每月的总销售量)</a>
								<div class="layuiadmin-btn-group"
									style="position: absolute; top: 0px;">
									<div class="layui-inline">
										<div class="layui-input-inline">
											<input type="text" class="layui-input year" id="dateFour"
												placeholder="请选择年份"
												style="height: 30px; width: 120px; position: relative; top: -2px; left: -10px;">
										</div>
									</div>
								</div>
							</div>
							<div class="layui-card-body">
								<table class="layui-table" lay-data="{height:315, url:'../../SalesStatistics/findAllSalesStatistics.action?num=2', page:true, id:'SalesStatistics',size:'sm',totalRow: true}" lay-filter="test">
								  <thead>
								    <tr>
								      <th lay-data="{field:'drugName', width:100,totalRowText: '合计：',fixed:'left'}">药品名称</th>
								      <th lay-data="{field:'oneMonth', width:80,totalRow: true}">1月</th>
								      <th lay-data="{field:'twoMonth', width:80,totalRow: true}">2月</th>
								      <th lay-data="{field:'threeMonth', width:80,totalRow: true}">3月</th>
								      <th lay-data="{field:'fourMonth', width:80,totalRow: true}">4月</th>
								      <th lay-data="{field:'fiveMonth', width:80,totalRow: true}">5月</th>
								      <th lay-data="{field:'sixMonth', width:80,totalRow: true}">6月</th>
								      <th lay-data="{field:'sevenMonth', width:80,totalRow: true}">7月</th>
								      <th lay-data="{field:'eightMonth', width:80,totalRow: true}">8月</th>
								      <th lay-data="{field:'nineMonth', width:80,totalRow: true}">9月</th>
								      <th lay-data="{field:'tenMonth'}, width:80,totalRow: true">10月</th>
								      <th lay-data="{field:'elevenMonth', width:80,totalRow: true}">11月</th>
								      <th lay-data="{field:'twelveMonth', width:80,totalRow: true}">12月</th>
								      <th lay-data="{field:'sumNumber', width:80,totalRow: true}">年销量</th>
								    </tr>
								  </thead>
								</table>
							</div>
						</div>
					</div>
					<div class="layui-col-sm6">
						<div class="layui-card">
							<div class="layui-card-header">
								财务记录信息
								<div class="layuiadmin-btn-group layui-form" style="position: absolute; top: 0px;">
									<div class="layui-input-inline" style="width:120px;">
										<select name="FinancialRecord" lay-verify="" lay-search lay-filter="type">
											<option value="">收入/支出</option>
											<option value="收入">收入</option>
											<option value="支出">支出</option>
										</select>
									</div>
								</div>
							</div>
							<div class="layui-card-body">
								<table class="layui-table" lay-data="{height:315, url:'../../FinancialRecord/findByFsId.action', page:true, id:'FinancialRecord',size:'sm',totalRow: true}" lay-filter="test">
								  <thead>
								    <tr>
								      <th lay-data="{field:'frId', width:116,totalRowText: '合计：'}">财务记录ID</th>
								      <th lay-data="{field:'frName', width:120}">支出或收入</th>
								      <th lay-data="{field:'frSumprice', width:120,totalRow: true}">财务记录总金额</th>
								      <th lay-data="{field:'frRemark', width:120}">财务记录备注</th>
								      <th lay-data="{field:'frTimes', width:144}">时间</th>
								      <th lay-data="{fixed:'right', width:130,align:'center',toolbar: '#barDemos'}">操作</th>
								    </tr>
								  </thead>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-col-sm8" style="width:100%">
				<div class="layui-row layui-col-space15">
					<div class="layui-col-sm6">
						<div class="layui-card">
							<div class="layui-card-header">
								<a name="inventoryRecord"><a href="javascript:;" class="yujing" id="drugRepertory" style="border-bottom:	2px solid #5FB878;padding-bottom:4px;">药品库存预警</a></a>&nbsp;&nbsp;/&nbsp;&nbsp;<a href="javascript:;" class="yujing" id="materialsRepertory" style="padding-bottom:2px;">材料库存预警</a>
								<div class="layuiadmin-btn-group layui-form" style="position: absolute; top: 0px;">
									<div class="layui-input-inline" style="width:120px;">
										<a id="addOrDetails" name="drugSalesProportion" numOne="" numTwo="" typeOne="add" typeTwo="add" class="layui-btn layui-btn-xs">添加生产计划单</a>
									</div>
								</div>
							</div>
							<div class="layui-card-body" id="drugSalesProportion">
								<table class="layui-table" lay-data="{height:315, url:'../../Repertory/findAllDrugOrMaterials.action?condition=drug&warning=jinggao', page:true, id:'drugLackOfStock',size:'sm'}" lay-filter="drugLackOfStock"  style="display:none">
								  <thead>
								    <tr>
								      <th lay-data="{field: 'itemName', sort: 'true', align: 'center', width:182}">药品名称</th>
								      <th lay-data="{field: 'itemType', sort: 'true', align: 'center', width:120}">药品类型</th>
								      <th lay-data="{field: 'repNumber', sort: 'true', align: 'center', width:160}">数量</th>
								      <th lay-data="{align: 'center', width:160, toolbar: '#barDemoOne'}">操作</th>
								    </tr>
								  </thead>
								</table>
							</div>
							<div class="layui-card-body" id="materialsSalesProportion" style="display:none">
								<table class="layui-table" lay-data="{height:315, url:'../../Repertory/findAllDrugOrMaterials.action?condition=materials&warning=jinggao', page:true, id:'materialsLackOfStock',size:'sm'}" lay-filter="materialsLackOfStock"  style="display:none">
								  <thead>
								    <tr>
								      <th lay-data="{field: 'itemName', sort: 'true', align: 'center', width:182}">材料名称</th>
								      <th lay-data="{field: 'itemType', sort: 'true', align: 'center', width:120}">材料类型</th>
								      <th lay-data="{field: 'repNumber', sort: 'true', align: 'center', width:160}">数量</th>
								      <th lay-data="{align: 'center', width:160, toolbar: '#barDemoTwo'}">操作</th>
								    </tr>
								  </thead>
								</table>
							</div>
						</div>
					</div>
					<div class="layui-col-sm6">
						<div class="layui-card">
							<div class="layui-card-header">
								库存记录信息
								<div class="layuiadmin-btn-group layui-form" style="position: absolute; top: 0px;">
									<div class="layui-input-inline" style="width:120px;">
										<select name="InventoryRecord" lay-verify="" lay-search style="border:none;" lay-filter="type">
											<option value="">入库/出库</option>
											<option value="入库">入库</option>
											<option value="出库">出库</option>
										</select>
									</div>
								</div>
							</div>
							<div class="layui-card-body" id="salesProportion">
								<table class="layui-table" lay-data="{height:315, url:'../../InventoryRecord/findByFilId.action', page:true, id:'InventoryRecord',size:'sm',totalRow: true}" lay-filter="test">
								  <thead>
								    <tr>
								      <th lay-data="{field:'numbers', width:100,totalRowText: '合计：',fixed:'left'}">批次号</th>
								      <th lay-data="{field:'matNum', width:80,totalRow: true}">物品数量</th>
								      <th lay-data="{field:'irType', width:80}">记录类型</th>
								      <th lay-data="{field:'irRemark', width:80}">记录备注</th>
								      <th lay-data="{field:'filName', width:100}">公司名称</th>
								      <th lay-data="{field:'irTimes', width:100}">出库/入库日期</th>
								      <th lay-data="{fixed:'right', width:130,align:'center',toolbar: '#barDemo'}">操作</th>
								    </tr>
								  </thead>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- <div class="layui-col-sm8" style="width:100%">
				<div class="layui-row layui-col-space15">
					
					
				</div>
			</div> -->
		</div>
	</div>
	</div>

	<script src="../../layui/layui.js"></script>
	<script type="text/javascript" src="../../res/js/base.js"></script>
	<script src="../../res/js/tl/echarts.min.js"></script>
	<script type="text/javascript" src="../../res/js/jquery-1.10.2.js"></script>
	<script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-xs" lay-event="ck">查看记录详情</a>
	</script>
	<script type="text/html" id="barDemos">
      <a class="layui-btn layui-btn-xs" lay-event="detail">查看记录详情</a>
	</script>
	<script type="text/html" id="barDemoOne">
      <a class="layui-btn layui-btn-xs" lay-event="production" id="{{d.pwId}}" name="production" onclick="add(this);" num="0" itemName="{{d.itemName}}" drugId="{{d.pwId}}">加入生产计划单</a>
	</script>
	<script type="text/html" id="barDemoTwo">
      <a class="layui-btn layui-btn-xs" lay-event="purchase" id="{{d.pwId}}" name="purchase" onclick="add(this);" num="0" itemName="{{d.itemName}}" matId="{{d.pwId}}">加入采购单</a>
	</script>
	<script type="text/javascript">
		$(function(){
			var data = {"page":1,"limit":10,"num":1};
			chartOne(data);
			
			var data = {"page":1,"limit":6,"num":1};
			chartTwo(data);
			
			var data = {"page":1,"limit":6,"num":2};
			chartThree(data);
			
			var data = {"page":1,"limit":10};
			chartFour(data);
		});
		function chartOne(data){
			var url = getRootPath()+"SalesStatistics/findAllSalesStatistics.action";
			$.post(url,data,function(msg){
				var salesNumber = echarts.init(document.getElementById('salesNumber'));
				option = {
					    tooltip : {
					        trigger: 'axis',
					        axisPointer: {
					            type: 'cross',
					            label: {
					                backgroundColor: '#6a7985'
					            }
					        }
					    },
					    legend: {
					    	data : msg.drugName
					    },
					    toolbox: {
					        feature: {
					            saveAsImage: {}
					        }
					    },
					    grid: {
					        left: '1%',
					        right: '4%',
					        bottom: '3%',
					        containLabel: true
					    },
					    xAxis : [
					        {
					            type : 'category',
					            boundaryGap : false,
					            data:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
					        }
					    ],
					    yAxis : [
					        {
					            type : 'value'
					        }
					    ],
					    series : msg.list
					};
			    // 使用刚指定的配置项和数据显示图表。
			    salesNumber.setOption(option);
			 });
		}
		function chartTwo(data){
			var url = getRootPath()+"SalesStatistics/findTotalCostAllPriceAndSalesProfit.action";
			$.post(url,data,function(msg){
				var salesPrice = echarts.init(document.getElementById('salesPrice'));
				 option = {
					//color: ['#3398DB'],
				    tooltip : {
				    	trigger: 'axis'
				    },
				    legend: {
		                data:['销售总金额','成本总金额']
		            },
				    grid: {
				        left: '1%',
				        right: '4%',
				        bottom: '3%',
				        containLabel: true
				    },
				    toolbox: {
				        feature: {
				            saveAsImage: {}
				        }
				    },
				    xAxis : [
				        {
				            type : 'category',
				            data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
				            boundaryGap: false,
				        }
				    ],
				    yAxis : [
				        {
				            type : 'value'
				        }
				    ],
				    series : [
				    	{
				            name:'销售总金额',
				            type:'line',
				            data:msg.numTwo
				        },{
				            name:'成本总金额',
				            type:'line',
				            data:msg.numOne
				        }
				    ]
				};
			    // 使用刚指定的配置项和数据显示图表。
			    salesPrice.setOption(option);
			 });
		}
		function chartThree(data){
			var url = getRootPath()+"SalesStatistics/findTotalCostAllPriceAndSalesProfit.action";
			$.post(url,data,function(msg){
				var salesSumMoney = echarts.init(document.getElementById('salesSumMoney'));
				 option = {
					tooltip : {
				        trigger: 'axis',
				        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
				            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
				        }
				    },
				    legend: {
				        data:['销售总金额','毛利']
				    },
				    toolbox: {
				        feature: {
				            saveAsImage: {}
				        }
				    },
				    grid: {
				        left: '3%',
				        right: '4%',
				        bottom: '3%',
				        containLabel: true
				    },
				    xAxis : [
				        {
				            type : 'category',
				            data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
				        }
				    ],
				    yAxis : [
				        {
				            type : 'value'
				        }
				    ],
				    series : [
				        {
				            name:'销售总金额',
				            type:'bar',
				            stack: '金额',
				            data:msg.numTwo
				        },
				        {
				            name:'毛利',
				            type:'bar',
				            stack: '金额',
				            data:msg.numOne
				        }
				    ]
				};

			    // 使用刚指定的配置项和数据显示图表。
			    salesSumMoney.setOption(option);
			 });
		}
		function chartFour(data){
			var url = getRootPath()+"SalesStatistics/findSumNumber.action";
			$.post(url,data,function(msg){
				var salesProportion = echarts.init(document.getElementById('salesProportion'));
			    option = {
			    	    title : {
			    	        text: '排行前十药品年销量占总销量的百分比',
			    	        x:'center'
			    	    },
			    	    tooltip : {
			    	        trigger: 'item',
			    	        formatter: "{a} <br/>{b} : {c} ({d}%)"
			    	    },
			    	    legend: {
			    	        type: 'scroll',
			    	        orient: 'vertical',
			    	        right: 10,
			    	        top: 20,
			    	        bottom: 20
			    	    },
			    	    series : [
			    	        {
			    	            name: '药品名称',
			    	            type: 'pie',
			    	            radius : '55%',
			    	            center: ['40%', '50%'],
			    	            data: msg,
			    	            itemStyle: {
			    	                emphasis: {
			    	                    shadowBlur: 10,
			    	                    shadowOffsetX: 0,
			    	                    shadowColor: 'rgba(0, 0, 0, 0.5)'
			    	                }
			    	            }
			    	        }
			    	    ]
			    	};
			 	// 使用刚指定的配置项和数据显示图表。
			    salesProportion.setOption(option);
			 });
		}
		
	</script>
	<script type="text/javascript">
		//初始化数据表格
		layui.use('table',function(){
			var table = layui.table;
		});
	</script>
	<script>
		layui.use(['laydate','table','form'], function() {
			var laydate = layui.laydate
			,table = layui.table
			,form = layui.form;
			laydate.render({ 
			  elem: '#dateOne'
			  ,type: 'year'
			  ,done: function(value, date, endDate){
				   /*  console.log(value); //得到日期生成的值，如：2017-08-18
				    console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
				    console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。 */
				  	var data = {"filId":1,"page":1,"limit":10,"num":"1","salesYear":value};
					chartOne(data);
				  }
			});
			laydate.render({ 
				  elem: '#dateTwo'
				  ,type: 'year'
				  ,done: function(value, date, endDate){
					    /* console.log(value); //得到日期生成的值，如：2017-08-18
					    console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
					    console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。 */
					  	var data = {"filId":1,"page":1,"limit":6,"num":1,"salesYear":value};
						chartTwo(data);
						var data = {"filId":1,"page":1,"limit":6,"num":2,"salesYear":value};
						chartThree(data);
					  }
				});
			laydate.render({ 
				  elem: '#dateThree'
				  ,type: 'year'
				  ,done: function(value, date, endDate){
					    /* console.log(value); //得到日期生成的值，如：2017-08-18
					    console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
					    console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。 */
						var data = {"filId":1,"page":1,"limit":10,"salesYear":value};
						chartFour(data);
					  }
				});
			laydate.render({ 
				  elem: '#dateFour'
				  ,type: 'year'
				  ,done: function(value, date, endDate){
					   /*  console.log(value); //得到日期生成的值，如：2017-08-18
					    console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
					    console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。 */
					    table.reload('SalesStatistics',{
					    	page:{
					    		curr:1
					    	},
					    	where:{
					    		salesYear:value
					    	}
					    });
					  }
				});
			
			table.on('tool(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
				  var data = obj.data; //获得当前行数据
				  var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
				  var title = "";
				  var url = "";
				  if(layEvent === 'ck'){ //查看
					title = "库存记录详情";
					var pwId = data.pwId;
					var irType = data.irType;
					alert("业务ID"+pwId+" 记录类型  "+irType);
					//alert("pwId:"+pwId+"  frType:"+frType);
					if(irType == "零售"){
						alert("零售");
						url = "ZgsSellDetailShowList.html?soId="+pwId;
					}else if(irType == "批发"){
						alert("批发");
						url = "ZgsSellDetailShowList.html?soId="+pwId;
					}else if(irType == "总店销售"){
						alert("总店销售");
						url = "ZgsSellDetailShowList.html?soId="+pwId;
					}else if(irType == "药品入库"){
						alert("质检入库");
						url = "ZgsSellDetailShowList.html?soId="+pwId;
					}
				  } else if(layEvent == 'detail'){
				    title = "财务记录详情";
				    var pwId = data.pwId;
					var frType = data.frType;
					alert("pwId:"+pwId+"  frType:"+frType);
					var url = "";
					if(frType == "1"){
						url = "ZgsSellDetailShowList.html?soId="+pwId;
					}else if(frType == "2"){
						url = "ZgsSellDetailShowList.html?soId="+pwId;
					}else if(frType == "3"){
						url = "ZgsSellDetailShowList.html?soId="+pwId;
					}else if(frType == "4"){
						url = "ZgsSellDetailShowList.html?soId="+pwId;
					}else if(frType == "5"){
						url = "ZgsSellDetailShowList.html?soId="+pwId;
					}
				  }
				  layer.open({
					  type: 2,
					  title: title,
					  area : ['80%' , '85%'],//弹出框大小
					  shift:1,//弹出框动画效果
					  content: url //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
					});
				});
			
			/* table.on('tool()',function(obj){
				var data = obj.data; //获得当前行数据
				var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
				if(layEvent == 'production'){
					alert('您点击了去生产');
				}else if(layEvent == 'purchase'){
					alert('您点击了去采购');
				}
			}) */
			
			var $ = layui.$;
			$(".layui-icon-search").click(function(event){
				var value = $("#InventoryRecord").val();
				table.reload('InventoryRecord', {
					  page: {
					    curr: 1 //重新从第 1 页开始
					  },
					  where: { //设定异步数据接口的额外参数，任意设
						 matName:value  
					  }
				});
			});
			
			form.on('select(type)', function(data){
				  /* console.log(data.elem); //得到select原始DOM对象
				  console.log(data.value); //得到被选中的值
				  console.log(data.othis); //得到美化后的DOM对象 */
				  var name = $(data.elem).attr("name");
				  if(name == "InventoryRecord"){
					  table.reload('InventoryRecord', {
						  page: {
						    curr: 1 //重新从第 1 页开始
						  },
						  where: { //设定异步数据接口的额外参数，任意设
							 irType:data.value  
						  }
					});
				  }else if(name == "FinancialRecord"){
					  table.reload('FinancialRecord', {
						  page: {
						    curr: 1 //重新从第 1 页开始
						  },
						  where: { //设定异步数据接口的额外参数，任意设
							 frName:data.value  
						  }
					});
				  }
			});
			
			/* //查看政策维护详情
			$("#policyDetail").on('click',function(){
				//../wsz/PolicyList.html
				layer.open({
					  title: '政策维护'
					  ,type:2
					  ,area:['80%','80%']
					  ,content: '../wsz/PolicyList.html'
					}); 
			}); */
			
			var data = {"num":1};
			//查询今日销量
			findTodaysSalesOrMonthSales(data);
			//查询今日收入
			findTodaysIncomeOrMonthIncome(data);
			
			
			var data = {"num":2};
			//查询月销量
			findTodaysSalesOrMonthSales(data);
			//查询月收入
			findTodaysIncomeOrMonthIncome(data);
			
			//查询财务总金额
			var url = getRootPath()+"SalesStatistics/findSumMoney.action";
			var data = null;
			$.ajax({
				url:url,
				data:data,
				success:function(msg){
					$(".sumMoney").prepend(msg);
				}
			});
			
			//查询库存预警的个数
			var url = getRootPath()+"Repertory/findCount.action";
			var data = null;
			$.ajax({
				url:url,
				data:data,
				success:function(msg){
					$("#repertory_earlyWarning").text(msg);
				}
			});
			
			//查询政策维护
			findAll();
			
			$("#addOrDetails").attr("numOne",sessionStorage['numOne']);
			$("#addOrDetails").attr("numTwo",sessionStorage['numTwo']);
			var proId = $("#addOrDetails").attr("numOne");
			var poId = $("#addOrDetails").attr("numTwo");
			//alert(proId);
			//alert(poId);
			if(proId != ""){
				var url = getRootPath()+"SalesStatistics/findByProId.action";
				var data = {"proId":proId};
				$.ajax({
					url:url,
					data:data,
					success:function(msg){
						//alert(msg.operator);
						alert(msg.operator);
						if(msg.operator == "不存在"){
							$("#addOrDetails").text("添加生产计划单");
							$("#addOrDetails").attr("numOne","");
							$("#addOrDetails").attr("typeOne","add");
							sessionStorage['numOne'] = "";
						}else if(msg.operator != "未制造"){
							$("#addOrDetails").text("添加生产计划单");
							$("#addOrDetails").attr("numOne","");
							$("#addOrDetails").attr("typeOne","add");
							sessionStorage['numOne'] = "";
							layer.open({
								title:'提示',
								content:'您上次添加的生产计划单在制造中,不能再向该计划单中添加药品，请重新添加一个新的生产计划单'
							});
						}else{
							$("#addOrDetails").text("查看生产计划单详情");	
							$("#addOrDetails").attr("typeOne","detail");
						}
					},
					dataType:"JSON"
				});
			}
			
			if(poId != ""){
				var url = getRootPath()+"SalesStatistics/findByPoId.action";
				var data = {"poId":poId};
				$.ajax({
					url:url,
					data:data,
					success:function(msg){
						//alert(msg.poState);
						if(msg.poState == "不存在"){
							$("#addOrDetails").attr("numTwo","");
							$("#addOrDetails").attr("typeTwo","add");
							sessionStorage['numTwo'] = "";
						}else if(msg.poState != "未审核,未采购,未提交,未质检,未入库"){
							//$("#addOrDetails").text("添加采购单");
							$("#addOrDetails").attr("numTwo","");
							$("#addOrDetails").attr("typeTwo","add");
							sessionStorage['numTwo'] = "";
							layer.open({
								title:'提示',
								content:'您上次添加的采购单在采购中,不能再向该采购单中添加材料，请重新添加一个新的采购单'
							});
						}else{
							//$("#addOrDetails").text("查看采购单详情");	
							$("#addOrDetails").attr("typeTwo","detail");
						}
					},
					dataType:"JSON"
				});
			}
		 	
			$(".yujing").on('click',function(event){
				var id = $(event.target).attr("id");
				if(id == "drugRepertory"){
					$("#drugSalesProportion").show();
					$("#materialsRepertory").attr("style","border-bottom:none");
					$("#materialsSalesProportion").hide();
					$("#drugRepertory").attr("style","border-bottom:2px solid #5FB878;padding-bottom:4px;");
					var numOne = $("#addOrDetails").attr("numOne");
					$("#addOrDetails").attr("name","drugSalesProportion");
					if(numOne == ""){
						$("#addOrDetails").text("添加生产计划单");
						$("#addOrDetails").attr("typeOne","add");
					}else {
						$("#addOrDetails").text("查看计划单详情");	
						$("#addOrDetails").attr("typeOne","detail");
					}
					//$("#addOrDetails").attr("type","drugSalesProportion");
				}else if(id == "materialsRepertory"){
					$("#drugSalesProportion").hide();
					$("#drugRepertory").attr("style","border-bottom:none");
					$("#materialsSalesProportion").show();
					$("#materialsRepertory").attr("style","border-bottom:2px solid #5FB878;padding-bottom:4px;");
					var numTwo = $("#addOrDetails").attr("numTwo");
					$("#addOrDetails").attr("name","metailsSalesProportion");
					if(numTwo == ""){
						$("#addOrDetails").text("添加采购单");
						$("#addOrDetails").attr("typeTwo","add");
					}else {
						$("#addOrDetails").text("查看采购单详情");
						$("#addOrDetails").attr("typeTwo","detail");
					}
					//$("#addOrDetails").attr("type","metailsSalesProportion");
				}
				
			});
			
			/* $("#scjhd").on('click',function(){
				var html = $("#drugSalesProportion").html();
				layer.open({
					type: 1,
					  title: '123',
					  area : ['80%' , '85%'],//弹出框大小
					  shift:1,//弹出框动画效果
					  content: html //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
				});
			}) */
			var name = $("#addOrDetails").attr("name");
			if(name == "drugSalesProportion"){
				if($("#addOrDetails").attr("numOne") != ""){
					$("#addOrDetails").text("查看生产计划单详情");
					$("#addOrDetails").attr("typeOne","detail");
				}else {
					$("#addOrDetails").text("添加生产计划单");
					$("#addOrDetails").attr("typeOne","add");
				};
			}else{
				if($("#addOrDetails").attr("numTwo") != ""){
					$("#addOrDetails").text("查看采购单详情");
					$("#addOrDetails").attr("typeTwo","detail");
				}else {
					$("#addOrDetails").text("添加采购单详情");
					$("#addOrDetails").attr("typeTwo","add");
				};
			}
			
			$("#addOrDetails").on('click',function(event){
				var names = $(event.target).attr("name");
				//alert(name);
				if(names == "drugSalesProportion"){
					var typeOne = $(event.target).attr("typeOne");
					if(typeOne == "add"){
						//alert("添加生产计划单");
						layer.open({
							title:'添加生产计划单',
							type:2,
							area:['75%','70%'],
							content:'scjhAdd.html',
						});
						//sessionStorage['numOne'] = "123";
						//$("#addOrDetails").attr("numOne","123");
						//$("#addOrDetails").text("查看生产计划单详情");
						//$("#addOrDetails").attr("typeOne","detail")
					}else{
						alert("查看生产计划单详情");
						//sessionStorage['numOne'] = "";
						var proId = $(event.target).attr("numOne");
						layer.open({
							title:"药品生产计划详情",
							type:2,
							area:["80%","80%"],
							content:"drugProductionShowList.html?proId="+proId
						});
					}
				}else{
					var typeTwo = $(event.target).attr("typeTwo");
					if(typeTwo == "add"){
						//alert("添加采购单");
						layer.open({
							title:'添加采购单',
							type:2,
							area:['75%','70%'],
							content:'cgdAdd.html',
						});
					}else{
						alert("查看采购单详情");
						//sessionStorage['numTwo'] = "";
						var poId = $(event.target).attr("numTwo");
						layer.open({
							title:"药品生产计划详情",
							type:2,
							area:["80%","80%"],
							content:"poBreakdownShowList.html?poId="+poId
						});
					}
				}
			});
		});
		
		function findTodaysSalesOrMonthSales(data){
			var url = getRootPath()+"SalesStatistics/findTodaysSalesOrMonthSales.action";
			var data = data;
			$.ajax({
				url:url,
				data:data,
				success:function(msg){
					if(data.num == "1"){
						$("#todaysSales").prepend(msg);
					}else if(data.num == "2"){
						$("#monthSales").prepend(msg);
					}
				}
			});
		}
		
		function findTodaysIncomeOrMonthIncome(data){
			var url = getRootPath()+"SalesStatistics/findTodaysIncomeOrMonthIncome.action";
			var data = data;
			$.ajax({
				url:url,
				data:data,
				success:function(msg){
					if(data.num == "1"){
						$("#todaysIncome").prepend(msg);
					}else if(data.num == "2"){
						$("#monthIncome").prepend(msg);
					}
				}
			});
		}
		function findAll(){
			var url = "../../policy/findAll.action";
			var data = {"page":1,"limit":20};
			$.ajax({
				url:url,
				data:data,
				asycn:false,
				success:function(msg){
					for(var i=0;i<msg.data.length;i++){
						$("#centent_nr").append("<a href='javascript:ckzcwh(\""+msg.data[i].policyId+"\");'><div class='zc_centent'><span class='span'>"+msg.data[i].policyName+"</span>"
								+"<span class='span'>"+msg.data[i].time+"</span></div></a>");
					}
				}
			});
		}
		function ckzcwh(obj){
			layui.use('layer',function(){
				var layer = layui.layer; //弹层
				  layer.open({
					  type: 2,
					  title: '政策维护信息',
					  area : ['100%' , '100%'],//弹出框大小
					  shift:1,//弹出框动画效果
					  content: '../wsz/Policy.html?policyId='+obj //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
				  });
			});
		}
		function add(obj){
			var id = $(obj).attr("name");
			var num = $(obj).attr("num");
			layui.use(['layer'],function(){
				var layer = layui.layer;//弹出层
				if(id == "production"){
					var numberOne = $("#addOrDetails").attr("numOne");
					var drugId = $(obj).attr("drugId");
					if(numberOne == ""){
						layer.open({
							title:'提示',
							content:'您尚未添加生产计划单,是否立即添加生产计划单?'
						});
					}else {
						if(num == 0){
							/* $(obj).attr("num","1");
							$(obj).text("取消加入生产计划单");
							layer.msg('成功加入生产计划单!',{time:1200}); */
							var url = getRootPath()+"SalesStatistics/addDrugProduction.action";
							var data = {"drugId":drugId,"proId":numberOne};
							$.ajax({
								url:url,
								data:data,
								success:function(msg){
									var rows = msg.rows;
									var drpId = msg.drpId;
									if(rows > 0){
										layer.msg('加入成功',{time:1000},function(){
											$(obj).attr("num","1");
											$(obj).text("取消加入生产计划单");
											$(obj).attr("pwId",drpId);
										});
									}else {
										layer.msg('加入失败',{time:1000});
										//$(obj).attr("pwId",drpId);
									}
								},
								dataType:"JSON"
							});
						}else {
							/* $(obj).attr("num","0");
							$(obj).text("加入生产计划单");
							layer.msg('成功取消加入生产计划单!',{time:1200}); */
							var url = getRootPath()+"SalesStatistics/deleteDrugProduction.action";
							var drpId = $(obj).attr("pwId");
							var data = "";
							if(drpId != ""){
								data = {"drpId":drpId};
							}else{
								layer.msg('取消失败',{time:1000},function(){
									return;
								});
							}
							
							$.ajax({
								url:url,
								data:data,
								success:function(msg){
									if(msg > 0){
										layer.msg('取消成功',{time:1000},function(){
											$(obj).attr("num","0");
											$(obj).text("加入生产计划单");
										});
									}else {
										layer.msg('取消失败',{time:1000});
										//$(obj).attr("pwId",drpId);
									}
								},
								dataType:"JSON"
							});
						}
					}
				}else {
					var numberTwo = $("#addOrDetails").attr("numTwo");
					var matId = $(obj).attr("matId");
					var matName = $(obj).attr("itemName");
					if(numberTwo == ""){
						layer.open({
							title:'提示',
							content:'您尚未添加采购单,是否立即添加采购单?'
						});
					}else {
						if(num == 0){
							/* $(obj).attr("num","1");
							$(obj).text("取消加入采购单");
							layer.msg('成功加入采购单!',{time:1200}); */
							var url = getRootPath()+"SalesStatistics/addPoBreakdown.action";
							var data = {"matId":matId,"poId":numberTwo,"pobName":matName};
							$.ajax({
								url:url,
								data:data,
								success:function(msg){
									var rows = msg.rows;
									var pobId = msg.pobId;
									if(rows > 0){
										layer.msg('加入成功',{time:1000},function(){
											$(obj).attr("num","1");
											$(obj).text("取消加入采购单");
											$(obj).attr("pwId",pobId);
										});
									}else {
										layer.msg('加入失败',{time:1000});
										//$(obj).attr("pwId",drpId);
									}
								},
								dataType:"JSON"
							});
						}else {
							/* $(obj).attr("num","0");
							$(obj).text("加入采购单");
							layer.msg('成功取消加入采购单!',{time:1200}); */
							var url = getRootPath()+"SalesStatistics/deletePoBreakdown.action";
							var pobId = $(obj).attr("pwId");
							var data = "";
							if(pobId != ""){
								data = {"pobId":pobId};
							}else{
								layer.msg('取消失败',{time:1000},function(){
									return;
								});
							}
							
							$.ajax({
								url:url,
								data:data,
								success:function(msg){
									if(msg > 0){
										layer.msg('取消成功',{time:1000},function(){
											$(obj).attr("num","0");
											$(obj).text("加入采购单");
										});
									}else {
										layer.msg('取消失败',{time:1000});
										//$(obj).attr("pwId",drpId);
									}
								},
								dataType:"JSON"
							});
						}
					}
				}
			});
			
		}
		function pdOne(){
			var proId = $("#addOrDetails").attr("numOne");
			var url = getRootPath()+"SalesStatistics/findByProIds.action";
			var data = {"proId":proId};
			if(proId != ""){
				$.ajax({
					url:url,
					data:data,
					success:function(msg){
						for(var i=0;i<msg.length;i++){
							/* $(obj).attr("num","1");
							$(obj).text("取消加入生产计划单");
							$(obj).attr("pwId",drpId); */
							$("#"+msg[i].drugId).attr("num",1);
							$("#"+msg[i].drugId).text("取消加入生产计划单");
							$("#"+msg[i].drugId).attr("pwId",msg[i].drpId);
						}
					},
					dataType:"JSON"
				});
			}
			
		}
		function pdTwo(){
			var poId = $("#addOrDetails").attr("numTwo");
			var url = getRootPath()+"SalesStatistics/findByPoIds.action";
			var data = {"poId":poId};
			if(poId != ""){
				$.ajax({
					url:url,
					data:data,
					success:function(msg){
						for(var i=0;i<msg.length;i++){
							$("#"+msg[i].matId).attr("num",1);
							$("#"+msg[i].matId).text("取消加入采购单");
							$("#"+msg[i].matId).attr("pwId",msg[i].pobId);
							/* $(obj).attr("num","1");
							$(obj).text("取消加入采购单");
							$(obj).attr("pwId",pobId); */
						}
					},
					dataType:"JSON"
				});
			}
			
		}
	</script>

</body>
</html>